﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCNhomNguoiDung.ascx.cs"
    Inherits="Viewer.NhomNguoiDung.UserControls.UCNhomNguoiDung" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register src="UCNguoiDung.ascx" tagname="NguoiDung" tagprefix="uc1" %>
<ext:XScript runat="server">
    <script type="text/javascript">
        function grdNguoiDung_Command(command, record) {
            if (command == 'Delete') { 
                Ext.MessageBox.show({
                   title: 'Confirm',
                   msg: 'Bạn có chắc chắn xóa record này ko?',
                   icon: Ext.MessageBox.QUESTION,
                   buttons: Ext.MessageBox.YESNO,
                   fn: function(btn)
                   {
                    if(btn.toLowerCase()=='yes')
                    {
                        //Do Yes
                        #{storeNguoiDung_NhomNguoiDung}.remove(record);
                        #{storeNguoiDung}.add(record);
                        #{storeNguoiDung}.sort('Name', 'ASC');
                       
                    }
                   }
                });
            }
        }
        
        function GetNguoiDungIds(grid)
        {
            var msg = [];
            var records =grid.store.getRange();
            Ext.each(records, function (record) {
                msg.push(record.id);
		    });
		    return msg.join(",");
        }
    </script>
</ext:XScript>
<ext:Window ID="wdUCNhomNguoiDung" runat="server" Width="550" AutoHeight="true" Closable="false"
    Modal="true" Resizable="false"  Hidden="true" BodyCssClass="window">
    <Items>
        <ext:Container runat="server" Layout="FormLayout" LabelWidth="100" >
            <Items>
                <ext:TextField ID="txtTenNhom" runat="server" FieldLabel="Tên nhóm" Width="200" />
                <%--<ext:ComboBox ID="cboLoaiNhom" runat="server" FieldLabel="Loại nhóm" DisplayField="CodeValue" ValueField="CodeID" Width="200" >
                    <Store>
                        <ext:Store ID="storeLoaiNhom" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="CodeID">
                                    <Fields>
                                        <ext:RecordField Name="CodeIDCha" />
                                        <ext:RecordField Name="CodeValue" />
                                        <ext:RecordField Name="CodeID" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                </ext:ComboBox>--%>
                <ext:TextField ID="txtGhiChu" runat="server"  FieldLabel="Ghi chú" Width="200" />
            </Items>
        </ext:Container>
        <ext:Panel ID="pnlNguoiDung" runat="server" Title="Người Dùng" Layout="Fit" MonitorResize="true"
            Icon="User" Height="350">
            <Items>
                <ext:GridPanel ID="grdNguoiDung_NhomNguoiDung" runat="server" AutoExpandColumn="TenDangNhap"
                    EnableColumnMove="false">
                    <Store>
                        <ext:Store ID="storeNguoiDung_NhomNguoiDung" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="NguoiDungID">
                                    <Fields>
                                        <ext:RecordField Name="TenDangNhap" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <ColumnModel>
                        <Columns>
                            <ext:RowNumbererColumn />
                            <ext:Column Header="Tên Đăng Nhập" DataIndex="TenDangNhap" />
                            <ext:CommandColumn Width="50">
                                <Commands>
                                    <ext:GridCommand Icon="Delete" CommandName="Delete" Text="Xóa">
                                    </ext:GridCommand>
                                </Commands>                               
                            </ext:CommandColumn>
                        </Columns>
                    </ColumnModel>
                    <TopBar>
                        <ext:Toolbar ID="Toolbar1" runat="server">
                            <Items>
                                <ext:Button runat="server" Icon="GroupLink" ID="btnShowDialogAddNguoiDung" Text="Thêm Người Dùng">
                                    <Listeners>
                                        <Click Handler="#{windowNguoiDung}.show();"></Click>
                                    </Listeners>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                    <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" PageIndex="1" />
                    </BottomBar>
                    <Listeners>
                        <Command Handler="grdNguoiDung_Command(command,record);" />
                        <%--edit here--%>
                    </Listeners>
                </ext:GridPanel>
                <ext:Hidden ID="__NguoiDungIds" runat="server">
                </ext:Hidden>
            </Items>
        </ext:Panel>
        <ext:Hidden ID="__NhomNguoiDungID" runat="server" Text=""></ext:Hidden>
        <ext:Hidden ID="__DialogType" runat="server" Text="" ></ext:Hidden>
    </Items>
    <Buttons>
        <ext:Button ID="btnSave" runat="server" Text="Lưu" Icon="Disk">
            <Listeners>
                <Click Handler="
                                if(#{txtTenNhom}.getValue().trim()=='')
                                {
                                    Ext.MessageBox.alert('Message', 'Xin vui lòng nhập Tên Nhóm !');                                   
                                    return false;
                                }
                                #{__NguoiDungIds}.setValue(GetNguoiDungIds(#{grdNguoiDung_NhomNguoiDung}));
                               
                             " />
            </Listeners>
            <DirectEvents>
                <Click OnEvent="btnSave_Click"></Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button ID="btnClose" runat="server" Text="Đóng" Icon="Cancel">
            <Listeners>
                <Click Handler="#{wdUCNhomNguoiDung}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
    <Listeners>
       
    </Listeners>
</ext:Window>
<uc1:NguoiDung ID="wdNguoiDung" runat="server"  />